package com.guodu.dao.impl;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.guodu.base.BaseDao;
import com.guodu.dao.PurchasingInformationTwoDao;
import com.guodu.entity.PurchasingInformationTwo;
import com.guodu.entity.PurchasinginfortwoStatus;
import com.guodu.entity.Units;
import com.guodu.vo.PurchasingInformationTwoQueryVo;
import com.guodu.vo.PurchasingInformationTwoVo;



@Repository("purchasingInformationTwoDao")
public class PurchasingInformationTwoDaoImpl extends BaseDao implements PurchasingInformationTwoDao {

	@Override
	public long findSizeByVo(PurchasingInformationTwoQueryVo pitq, Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("select count(*) from PurchasingInformationTwo m where 1=1");
		if(pitq!=null){
			if(pitq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pitq.getFunitsId()+" ) or m.unitsId ="+pitq.getFunitsId()+" )");
			}
			if(pitq.getUnitsId()!=null && !"".equals(pitq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pitq.getUnitsId()+"");
			}
			if (pitq.getProjectName()!=null && !"".equals(pitq.getProjectName())) {
				hql.append(" and projectName like '%"+pitq.getProjectName()+"%' ");
			}
			if (pitq.getProjectType()!=null && !"".equals(pitq.getProjectType())) {
				hql.append(" and projectType like '%"+pitq.getProjectType()+"%' ");
			}
			if (pitq.getProjectSituation()!=null && !"".equals(pitq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pitq.getProjectSituation()+"%' ");
			}
			if (pitq.getSectionName()!=null && !"".equals(pitq.getSectionName())) {
				hql.append(" and sectionName like '%"+pitq.getSectionName()+"%' ");
			}
			if (pitq.getSecName()!=null && !"".equals(pitq.getSecName())) {
				hql.append(" and secName like '%"+pitq.getSecName()+"%' ");
			}
			if (pitq.getSecUnits()!=null && !"".equals(pitq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pitq.getSecUnits()+"%' ");
			}
			if (pitq.getSecClassification()!=null && !"".equals(pitq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pitq.getSecClassification()+"%' ");
			}
			if (pitq.getProcurementMethod()!=null && !"".equals(pitq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pitq.getProcurementMethod()+"%' ");
			}
			if(pitq.getCreateBeginTime()!=null&&pitq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pitq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pitq.getCreateEndTime()!=null&&pitq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pitq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcbeginTime()!=null && !"".equals(pitq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pitq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcendTime()!=null && !"".equals(pitq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pitq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeBegin()!=null && !"".equals(pitq.getReviewTimeBegin())) {
				hql.append("    and reviewTime >= TO_DATE('"+pitq.getReviewTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeEnd()!=null && !"".equals(pitq.getReviewTimeEnd())) {
				hql.append("    and reviewTime <= TO_DATE('"+pitq.getReviewTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeBegin()!=null && !"".equals(pitq.getEndTimeBegin())) {
				hql.append("    and endTime >= TO_DATE('"+pitq.getEndTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeEnd()!=null && !"".equals(pitq.getEndTimeEnd())) {
				hql.append("    and endTime <= TO_DATE('"+pitq.getEndTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getPurchaseYears()!=null && !"".equals(pitq.getPurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') >= TO_DATE('"+pitq.getPurchaseYears()+"','yyyy-mm')");
			}
			if (pitq.getEpurchaseYears()!=null && !"".equals(pitq.getEpurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') <= TO_DATE('"+pitq.getEpurchaseYears()+"','yyyy-mm')");
			}
			if(pitq.getStatus()!=null&&pitq.getStatus().trim().length()>0&&!pitq.getStatus().equals("5")){
				hql.append(" and status ="+pitq.getStatus());
			}
		}
		if(units==null){
			hql.append("and (status=0 or status=3 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and (status=3 or status=0 or status=4)");
		}
		return super.findInt(hql.toString());
	}
	@Override
	public void examinAll(PurchasingInformationTwoQueryVo pitq, Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();
		if(units==null){
			hql.append("update from PurchasingInformationTwo m set m.status=3 where m.status=0 ");			
		}
		if(pitq!=null){
			if(pitq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pitq.getFunitsId()+" ) or m.unitsId ="+pitq.getFunitsId()+" )");
			}
			if(pitq.getUnitsId()!=null && !"".equals(pitq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pitq.getUnitsId()+"");
			}
			if (pitq.getProjectName()!=null && !"".equals(pitq.getProjectName())) {
				hql.append(" and projectName like '%"+pitq.getProjectName()+"%' ");
			}
			if (pitq.getProjectType()!=null && !"".equals(pitq.getProjectType())) {
				hql.append(" and projectType like '%"+pitq.getProjectType()+"%' ");
			}
			if (pitq.getProjectSituation()!=null && !"".equals(pitq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pitq.getProjectSituation()+"%' ");
			}
			if (pitq.getSectionName()!=null && !"".equals(pitq.getSectionName())) {
				hql.append(" and sectionName like '%"+pitq.getSectionName()+"%' ");
			}
			if (pitq.getSecName()!=null && !"".equals(pitq.getSecName())) {
				hql.append(" and secName like '%"+pitq.getSecName()+"%' ");
			}
			if (pitq.getSecUnits()!=null && !"".equals(pitq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pitq.getSecUnits()+"%' ");
			}
			if (pitq.getSecClassification()!=null && !"".equals(pitq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pitq.getSecClassification()+"%' ");
			}
			if (pitq.getProcurementMethod()!=null && !"".equals(pitq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pitq.getProcurementMethod()+"%' ");
			}
			if(pitq.getCreateBeginTime()!=null&&pitq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pitq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pitq.getCreateEndTime()!=null&&pitq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pitq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcbeginTime()!=null && !"".equals(pitq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pitq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcendTime()!=null && !"".equals(pitq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pitq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeBegin()!=null && !"".equals(pitq.getReviewTimeBegin())) {
				hql.append("    and reviewTime >= TO_DATE('"+pitq.getReviewTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeEnd()!=null && !"".equals(pitq.getReviewTimeEnd())) {
				hql.append("    and reviewTime <= TO_DATE('"+pitq.getReviewTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeBegin()!=null && !"".equals(pitq.getEndTimeBegin())) {
				hql.append("    and endTime >= TO_DATE('"+pitq.getEndTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeEnd()!=null && !"".equals(pitq.getEndTimeEnd())) {
				hql.append("    and endTime <= TO_DATE('"+pitq.getEndTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getPurchaseYears()!=null && !"".equals(pitq.getPurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') >= TO_DATE('"+pitq.getPurchaseYears()+"','yyyy-mm')");
			}
			if (pitq.getEpurchaseYears()!=null && !"".equals(pitq.getEpurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') <= TO_DATE('"+pitq.getEpurchaseYears()+"','yyyy-mm')");
			}
			if(pitq.getStatus()!=null&&pitq.getStatus().trim().length()>0&&!pitq.getStatus().equals("5")){
				hql.append(" and status ="+pitq.getStatus());
			}
		}
		if(units==null){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and (status=3 or status=0 or status=4)");
		}
		super.executeUpdate(hql.toString());		
	}

	@Override
	public void save(PurchasingInformationTwo purchasingInformationTwo) {
		// TODO Auto-generated method stub
		super.save(purchasingInformationTwo);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PurchasingInformationTwo> findByVo(
			PurchasingInformationTwoQueryVo pitq, Units units, int curPage,
			int pageSize) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("from PurchasingInformationTwo m where 1=1");
		if(pitq!=null){
			if(pitq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pitq.getFunitsId()+" ) or m.unitsId ="+pitq.getFunitsId()+" )");
			}
			if(pitq.getUnitsId()!=null && !"".equals(pitq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pitq.getUnitsId()+"");
			}
			if (pitq.getProjectName()!=null && !"".equals(pitq.getProjectName())) {
				hql.append(" and projectName like '%"+pitq.getProjectName()+"%' ");
			}
			if (pitq.getProjectType()!=null && !"".equals(pitq.getProjectType())) {
				hql.append(" and projectType like '%"+pitq.getProjectType()+"%' ");
			}
			if (pitq.getProjectSituation()!=null && !"".equals(pitq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pitq.getProjectSituation()+"%' ");
			}
			if (pitq.getSectionName()!=null && !"".equals(pitq.getSectionName())) {
				hql.append(" and sectionName like '%"+pitq.getSectionName()+"%' ");
			}
			if (pitq.getSecName()!=null && !"".equals(pitq.getSecName())) {
				hql.append(" and secName like '%"+pitq.getSecName()+"%' ");
			}
			if (pitq.getSecUnits()!=null && !"".equals(pitq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pitq.getSecUnits()+"%' ");
			}
			if (pitq.getSecClassification()!=null && !"".equals(pitq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pitq.getSecClassification()+"%' ");
			}
			if (pitq.getProcurementMethod()!=null && !"".equals(pitq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pitq.getProcurementMethod()+"%' ");
			}
			if(pitq.getCreateBeginTime()!=null&&pitq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pitq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pitq.getCreateEndTime()!=null&&pitq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pitq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcbeginTime()!=null && !"".equals(pitq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pitq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcendTime()!=null && !"".equals(pitq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pitq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeBegin()!=null && !"".equals(pitq.getReviewTimeBegin())) {
				hql.append("    and reviewTime >= TO_DATE('"+pitq.getReviewTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeEnd()!=null && !"".equals(pitq.getReviewTimeEnd())) {
				hql.append("    and reviewTime <= TO_DATE('"+pitq.getReviewTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeBegin()!=null && !"".equals(pitq.getEndTimeBegin())) {
				hql.append("    and endTime >= TO_DATE('"+pitq.getEndTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeEnd()!=null && !"".equals(pitq.getEndTimeEnd())) {
				hql.append("    and endTime <= TO_DATE('"+pitq.getEndTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getPurchaseYears()!=null && !"".equals(pitq.getPurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') >= TO_DATE('"+pitq.getPurchaseYears()+"','yyyy-mm')");
			}
			if (pitq.getEpurchaseYears()!=null && !"".equals(pitq.getEpurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') <= TO_DATE('"+pitq.getEpurchaseYears()+"','yyyy-mm')");
			}
			if(pitq.getStatus()!=null&&pitq.getStatus().trim().length()>0&&!pitq.getStatus().equals("5")){
				hql.append(" and status ="+pitq.getStatus());
			}
		}
		if(units==null){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and (status=3 or status=0 or status=4)");
		}
		hql.append(" order by purchaseId desc");
		return super.findPages(hql.toString(), curPage, pageSize);
	}

	@Override
	public PurchasingInformationTwo findById(String purchaseId) {
		// TODO Auto-generated method stub
		return (PurchasingInformationTwo) super.findById(PurchasingInformationTwo.class, purchaseId);
	}

	@Override
	public void update(PurchasingInformationTwo purchasingInformationTwo) {
		// TODO Auto-generated method stub
		super.update(purchasingInformationTwo);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PurchasinginfortwoStatus> findStatus(String purchaseId) {
		// TODO Auto-generated method stub
		return super.findByProperty(PurchasinginfortwoStatus.class, "purchaseId", purchaseId);
	}

	@Override
	public void changeStatus(List<PurchasinginfortwoStatus> entities) {
		// TODO Auto-generated method stub
		super.saveAll(entities);
	}

	@Override
	public void examine(String ids, Long status) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("update PurchasingInformationTwo set status =");
		hql.append(status);
		hql.append(" where purchaseId in (");
		hql.append(ids);
		hql.append(")");
		super.executeUpdate(hql.toString());
	}

	@Override
	public void delByIds(String[] delIds) {
		// TODO Auto-generated method stub
		super.deleteAllById(PurchasingInformationTwo.class, delIds);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PurchasingInformationTwo> findAllByVo(
			PurchasingInformationTwoQueryVo pitq, Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("from PurchasingInformationTwo m where 1=1");
		if(pitq!=null){
			if(pitq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pitq.getFunitsId()+" ) or m.unitsId ="+pitq.getFunitsId()+" )");
			}
			if(pitq.getUnitsId()!=null && !"".equals(pitq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pitq.getUnitsId()+"");
			}
			if (pitq.getProjectName()!=null && !"".equals(pitq.getProjectName())) {
				hql.append(" and projectName like '%"+pitq.getProjectName()+"%' ");
			}
			if (pitq.getProjectType()!=null && !"".equals(pitq.getProjectType())) {
				hql.append(" and projectType like '%"+pitq.getProjectType()+"%' ");
			}
			if (pitq.getProjectSituation()!=null && !"".equals(pitq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pitq.getProjectSituation()+"%' ");
			}
			if (pitq.getSectionName()!=null && !"".equals(pitq.getSectionName())) {
				hql.append(" and sectionName like '%"+pitq.getSectionName()+"%' ");
			}
			if (pitq.getSecName()!=null && !"".equals(pitq.getSecName())) {
				hql.append(" and secName like '%"+pitq.getSecName()+"%' ");
			}
			if (pitq.getSecUnits()!=null && !"".equals(pitq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pitq.getSecUnits()+"%' ");
			}
			if (pitq.getSecClassification()!=null && !"".equals(pitq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pitq.getSecClassification()+"%' ");
			}
			if (pitq.getProcurementMethod()!=null && !"".equals(pitq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pitq.getProcurementMethod()+"%' ");
			}
			if(pitq.getCreateBeginTime()!=null&&pitq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pitq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pitq.getCreateEndTime()!=null&&pitq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pitq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcbeginTime()!=null && !"".equals(pitq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pitq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcendTime()!=null && !"".equals(pitq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pitq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeBegin()!=null && !"".equals(pitq.getReviewTimeBegin())) {
				hql.append("    and reviewTime >= TO_DATE('"+pitq.getReviewTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeEnd()!=null && !"".equals(pitq.getReviewTimeEnd())) {
				hql.append("    and reviewTime <= TO_DATE('"+pitq.getReviewTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeBegin()!=null && !"".equals(pitq.getEndTimeBegin())) {
				hql.append("    and endTime >= TO_DATE('"+pitq.getEndTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeEnd()!=null && !"".equals(pitq.getEndTimeEnd())) {
				hql.append("    and endTime <= TO_DATE('"+pitq.getEndTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getPurchaseYears()!=null && !"".equals(pitq.getPurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') >= TO_DATE('"+pitq.getPurchaseYears()+"','yyyy-mm')");
			}
			if (pitq.getEpurchaseYears()!=null && !"".equals(pitq.getEpurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') <= TO_DATE('"+pitq.getEpurchaseYears()+"','yyyy-mm')");
			}
			if(pitq.getStatus()!=null&&pitq.getStatus().trim().length()>0&&!pitq.getStatus().equals("5")){
				hql.append(" and status ="+pitq.getStatus());
			}
		}
		if(units==null){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and (status=3 or status=0 or status=4)");
		}
		hql.append("order by createTime desc");
		return super.find(hql.toString());
	}

	@Override
	public PurchasingInformationTwoVo findAllMoney(
			PurchasingInformationTwoQueryVo pitq, Units units) {
		StringBuffer hql = new StringBuffer("select sum(secEvaluation),sum(sectionEvaluation),sum(tenderOffer),sum(bidEvaluation),sum(saveMoney) from PurchasingInformationTwo m where 1=1");
		if(pitq!=null){
			if(pitq.getFunitsId()!=null){
				hql.append("    and (exists(select 1 from Units u where u.unitsId = m.unitsId and u.funitsId="+pitq.getFunitsId()+" ) or m.unitsId ="+pitq.getFunitsId()+" )");
			}
			if(pitq.getUnitsId()!=null && !"".equals(pitq.getUnitsId())){
				hql.append(" and  m.unitsId = "+pitq.getUnitsId()+"");
			}
			if (pitq.getProjectName()!=null && !"".equals(pitq.getProjectName())) {
				hql.append(" and projectName like '%"+pitq.getProjectName()+"%' ");
			}
			if (pitq.getProjectType()!=null && !"".equals(pitq.getProjectType())) {
				hql.append(" and projectType like '%"+pitq.getProjectType()+"%' ");
			}
			if (pitq.getProjectSituation()!=null && !"".equals(pitq.getProjectSituation())) {
				hql.append(" and projectSituation like '%"+pitq.getProjectSituation()+"%' ");
			}
			if (pitq.getSectionName()!=null && !"".equals(pitq.getSectionName())) {
				hql.append(" and sectionName like '%"+pitq.getSectionName()+"%' ");
			}
			if (pitq.getSecName()!=null && !"".equals(pitq.getSecName())) {
				hql.append(" and secName like '%"+pitq.getSecName()+"%' ");
			}
			if (pitq.getSecUnits()!=null && !"".equals(pitq.getSecUnits())) {
				hql.append(" and secUnits like '%"+pitq.getSecUnits()+"%' ");
			}
			if (pitq.getSecClassification()!=null && !"".equals(pitq.getSecClassification())) {
				hql.append(" and secClassification like '%"+pitq.getSecClassification()+"%' ");
			}
			if (pitq.getProcurementMethod()!=null && !"".equals(pitq.getProcurementMethod())) {
				hql.append(" and procurementMethod like '%"+pitq.getProcurementMethod()+"%' ");
			}
			if(pitq.getCreateBeginTime()!=null&&pitq.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+pitq.getCreateBeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(pitq.getCreateEndTime()!=null&&pitq.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+pitq.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcbeginTime()!=null && !"".equals(pitq.getFcbeginTime())) {
				hql.append("    and issueTime >= TO_DATE('"+pitq.getFcbeginTime()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getFcendTime()!=null && !"".equals(pitq.getFcendTime())) {
				hql.append("    and issueTime <= TO_DATE('"+pitq.getFcendTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeBegin()!=null && !"".equals(pitq.getReviewTimeBegin())) {
				hql.append("    and reviewTime >= TO_DATE('"+pitq.getReviewTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getReviewTimeEnd()!=null && !"".equals(pitq.getReviewTimeEnd())) {
				hql.append("    and reviewTime <= TO_DATE('"+pitq.getReviewTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeBegin()!=null && !"".equals(pitq.getEndTimeBegin())) {
				hql.append("    and endTime >= TO_DATE('"+pitq.getEndTimeBegin()+" 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getEndTimeEnd()!=null && !"".equals(pitq.getEndTimeEnd())) {
				hql.append("    and endTime <= TO_DATE('"+pitq.getEndTimeEnd()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if (pitq.getPurchaseYears()!=null && !"".equals(pitq.getPurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') >= TO_DATE('"+pitq.getPurchaseYears()+"','yyyy-mm')");
			}
			if (pitq.getEpurchaseYears()!=null && !"".equals(pitq.getEpurchaseYears())) {
				hql.append("    and TO_DATE(purchaseYears,'yyyy-mm') <= TO_DATE('"+pitq.getEpurchaseYears()+"','yyyy-mm')");
			}
			if(pitq.getStatus()!=null&&pitq.getStatus().trim().length()>0&&!pitq.getStatus().equals("5")){
				hql.append(" and status ="+pitq.getStatus());
			}
		}
		if(units==null){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==1){
			hql.append("and (status=3 or status=0 or status=4)");
		}else if(units.getUnitsLevel()==1L&&units.getIsComplete()==0){
			hql.append("and (status=3 or status=0 or status=4)");
		}
		PurchasingInformationTwoVo p = new PurchasingInformationTwoVo();
		List<Object[]> objs = super.find(hql.toString());
		if(objs.size()>0){
			DecimalFormat df = new DecimalFormat("##,###.##");
			try {
				if(objs.get(0)[0]!=null){
					p.setAllMoney1(df.format(df.parse(objs.get(0)[0].toString())));
				}
                if(objs.get(0)[1]!=null){
                	p.setAllMoney2(df.format(df.parse(objs.get(0)[1].toString())));
				}
                if(objs.get(0)[2]!=null){
                	p.setAllMoney3(df.format(df.parse(objs.get(0)[2].toString())));
				}
                if(objs.get(0)[3]!=null){
                	p.setAllMoney4(df.format(df.parse(objs.get(0)[3].toString())));
				}
                if(objs.get(0)[4]!=null){
                	p.setAllMoney5(df.format(df.parse(objs.get(0)[4].toString())));
				}
			}catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return p;
	}

	

}
